﻿/// <reference path="zhx.js" />
var strMenu = "";
var bjOne = true;
$(function() {
    strMenu = "";
    bjOne = true;
    tomenu(menuJson, "0");
    $("#menu").html(strMenu);
    $("#menuTree").tree({ animate: true });
//    $("#menuTree li").each(function(i) {
//        $(this).find("span.tree-hit:first").trigger("click");
//        $(this).find("span.tree-folder:first").click(function() {
//            $(this).parent().find("span.tree-hit").trigger("click");
//        });
//    });
});
function aa(obj) {
    $(obj).parent().find("span.tree-hit").trigger("click");
}
function bb(obj, url) {
    if ($("#tab").tabs('exists', $(obj).text())) {
        $("#" + $(obj).html()).attr("src", url);
        $("#tab").tabs('select', $(obj).text());
    } else {
        $("#tab").tabs('add', {
            title: $(obj).text(),
            content: "<iframe id=\"" + $(obj).text() + "\" name=\"" + $(obj).text() + "\" scrolling=\"yes\" frameborder=\"0\" scrolling=\"no\" allowtransparency=\"true\"  src=\"" + url + "\" style=\"width:100%;height:100%;\"></iframe>",
            closable: true
        });
    }
}
function tomenu(json, id) {
    var bjC = true;
    $(json).each(function(i) {
        if (this.Pid == id) {
            if (bjOne) {
                strMenu += "<ul id=\"menuTree\">";
                bjOne = false;
                bjC = false;
            } else if (bjC) {
                strMenu += "<ul>";
                bjC = false;
            }
            var _icon = "";
            if ($.trim(this.Icon) != "") {
                //_icon = "class=\"" + this.Icon + "\"";
            }
            if ($.trim(this.Url) == "") {
                strMenu += "<li " + _icon + "><span onclick=\"aa(this);\">" + this.Name + "</span>";
            } else {
                strMenu += "<li " + _icon + "><span onclick=\"bb(this,'" + this.Url + "');\">" + this.Name + "</span>";
            }
            tomenu(json, this.Id);
            strMenu += "</li>";
        }
    });
    if (!bjC) {
        strMenu += "</ul>";
    }
}
function pdtab(id) {
    $("#tab div.tabs-wrap li span").each(function(i) {
        if ($(this).html() != "") {
            if ($(this).css("font-weight") == "700" || $(this).css("font-weight") == "bold") {
                if (id == 1) {
                    window.parent.frames[$(this).text()].history.back();
                } else if (id == 2) {
                    window.parent.frames[$(this).text()].history.forward();
                } else if (id == 3) {
                    window.parent.frames[$(this).text()].location.reload();
                }
            }
        }
    });
}

function closeall() {
    $(".tabs-close").trigger("click");
}